package taobao;

import java.util.ArrayList;
import java.util.List;

/** 
  * @author  outsider
  * @date 创建时间：2016年4月20日 下午8:33:16 
  * @note
*/
public class CheckDisount {
   public static Order discout(Order order){
	   List<Discount> listDicount=new ArrayList<>();
	   
	   
	   Discount discount1=new RedPacketDiscount(10, 100);
	   Discount discount2=new RedPacketDiscount(30, 300);
	   Discount discount3=new FreeFreightDiscount(100);
	   
	   listDicount.add(discount1);
	   listDicount.add(discount2);
	   listDicount.add(discount3);
	   
	   Discount choose=null;
	   int maxDiscountFee=0;
	   for (Discount discount:listDicount){
		   discount.useDiscount(order);
		   if (order.getDiscountFee()>maxDiscountFee){
			   choose=discount;
			   maxDiscountFee=order.getDiscountFee();
		   }
	   }
	   order.setDiscount(choose);
	   order.setDiscountFee(maxDiscountFee);
	   
	   return order;
   }
}
